PLAY Statement (Music) ---------------------------------------------------------------------------- Action Plays music as specified by a string. Syntax PLAY commandstring$ Remarks The commandstring$ argument is a string expression that contains one or more music commands listed later in this entry. The PLAY statement uses a concept similar to DRAW in that it embeds a music macro language (described below) in one statement. A set of commands, used as part of the PLAY statement, specifies a particular action. The VARPTR$( variablename) form for variables must be used with DRAW and PLAY (music) statements in BASIC to execute substrings that contain variables. BASICA supports both the VARPTR$ syntax and the syntax containing just the variable name. For example, consider these BASICA statements. PLAY "XA$" PLAY "O = I" For BASIC programs, those statements should be written like this. PLAY "X" + VARPTR$(A$) PLAY "O=" + VARPTR$(I) The commandstring$ music commands are described as follows. ----------------------------------------------------------------------------- Command Action ---------------------------------------------------------------------------- Octave command o n Sets the current octave. There are seven octaves, numbered 0-6. > Increases octave by 1. Octave cannot go beyond 6. < Decreases octave by 1. Octave cannot drop below 0. Tone command Command Action ---------------------------------------------------------------------------- A - G Plays a note in the range A - G. The number sign (#) or the plus sign (+) after a note specifies sharp; a minus sign (-) specifies flat. N n Plays note n. The range for n is 0 - 84 (in the seven possible octaves, there are 84 notes); an n value of 0 means a rest. Duration command L n Sets the length of each note. L4 is a quarter note, L1 is a whole note, etc. The range for n is 1 - Command Action ---------------------------------------------------------------------------- note, etc. The range for n is 1 - 64. The length can also follow the note when a change of length only is desired for a particular note. For example, A16 can be equivalent to L16A. MN Sets "music normal" so that each note will play 7-8 of the time determined by the length (L). ML Sets "music legato" so that each note will play the full period set by length (L). MS Sets "music staccato" so that each note will play 3-4 of the time determined by the length (L). Command Action ---------------------------------------------------------------------------- Tempo command P n Specifies a pause, ranging from 1 to 64. This option corresponds to the length of each note, set with L n. T n Sets the "tempo," or the number of L4 quarter notes in one minute. The range for n is 32-255. The default for n is 120. Because of the slow clock-interrupt rate, some notes will not play at higher tempos (L64 at T255, for example). Command Action ---------------------------------------------------------------------------- (L64 at T255, for example). Mode command MF Sets music ( PLAY statement) and SOUND to run in the foreground. That is, each subsequent note or sound will not start until the previous note or sound has finished. This is the default setting. MB Music ( PLAY statement) and SOUND are set to run in the background. That is, each note or sound is placed in a buffer, allowing the BASIC program to continue Command Action ---------------------------------------------------------------------------- BASIC program to continue executing while the note or sound plays in the background. The maximum number of notes that can be played in the background at one time is 32. Suffix # or + Follows a specified note and turns it into a sharp. - Follows a specified note and turns it into a flat.. . A period after a note causes the note to play one-and-a-half times Command Action ---------------------------------------------------------------------------- note to play one-and-a-half times the length determined by L*T (length times tempo). The period has the same meaning as in a musical score. Multiple periods can appear after a note. Each period adds a length equal to one-half the length of the previous period. For example, the command A . plays 1 + 1-2, or 3-2 times the length; A.. plays 1 + 1-2 + 1-4, or 7-4 times the length. Periods can appear after a pause (P). In this case, the pause length is scaled in the same way notes are scaled. Command Action ---------------------------------------------------------------------------- Substring command "X" + VARPTR$(string) Executes a substring. This powerful command enables you to execute a second substring from a string. You can have one string expression execute another, which executes a third, and so on. Note The PLAY statement is not available in OS-2 protected mode. See Also BEEP, ON event, PLAY Function, PLAY Statements (Event Trapping), SOUND Example See the PLAY function programming example, which uses the PLAY statement.